import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

/**
 * SideBar
 * Holds the buttons for the user to perform actions
 *
 *
 *  Date           	Name            	Action
 *  --------------------------------------------------------------------------------------
 *	03/06/11		Bethany				Created Class
 *
 *
 *
 * @author bethanysumner
 * @version $Revision: 1.0 $
 */

public class SideBar extends JPanel{
	
	/**
	 * Field main.
	 */
	private MainWindow main;
	
	/**
	 * Field buttonListener.
	 */
	private ButtonListener buttonListener;
	/**
	 * Field btnHelp.
	 */
	private JButton btnHelp;
	/**
	 * Field btnLogout.
	 */
	private JButton btnLogout;
	/**
	 * Field btnRequestAppt.
	 */
	private JButton btnRequestAppt;
	/**
	 * Field btnUpdateInfo.
	 */
	private JButton btnUpdateInfo;
	/**
	 * Field btnMedHistory.
	 */
	private JButton btnMedHistory;
	/**
	 * Field btnViewUsers.
	 */
	private JButton btnViewUsers;
	/**
	 * Field btnAddNewUser.
	 */
	private JButton btnAddNewUser;
	/**
	 * Field btnViewAppts.
	 */
	private JButton btnViewAppts;
	/**
	 * Field btnViewIncome.
	 */
	private JButton btnViewIncome;
	/**
	 * Field btnViewPatients.
	 */
	private JButton btnViewPatients;
	/**
	 * Field btnViewInvoice.
	 */
	private JButton btnViewInvoice;
	/**
	 * Field btnViewWeightChart.
	 */
	private JButton btnViewWeightChart;
	
	/**
	 * SideBar Constructor
	 * @param usertype The user type of the current user (must be a digit 0-3)
	 * @param main MainWindow
	 */
	public SideBar(MainWindow main, int usertype){
		
		this.main = main;
		
		// setup layout
		setPreferredSize(new Dimension(200,600));
		setLayout(new FlowLayout(FlowLayout.CENTER, 200, 5));
		
		// create button listener
		buttonListener = new ButtonListener();
		
		switch(usertype){
		case 0:
			addSysAdminBtns();
			break;
		case 1:
			addDoctorBtns();
			break;
		case 2:
			addNurseBtns();
			break;
		case 3:
			addPatientBtns();
			break;
		}

		// add buttons visible to everyone
		btnLogout = new JButton("Logout");
		btnLogout.addActionListener(buttonListener);
		add(btnLogout);
		
		
	}//end SideBar(main, usertype)

	
	
	/**
	 * Adds buttons that correspond to system admin actions
	 */
	private void addSysAdminBtns(){
		
		btnViewUsers = new JButton("View Users");
		btnViewUsers.addActionListener(buttonListener);
		add(btnViewUsers);
		
		btnAddNewUser = new JButton("Add New User");
		btnAddNewUser.addActionListener(buttonListener);
		add(btnAddNewUser);
		
		btnViewAppts = new JButton("View Appointments");
		btnViewAppts.addActionListener(buttonListener);
		add(btnViewAppts);
		
		btnViewIncome = new JButton("View Income Statement");
		btnViewIncome.addActionListener(buttonListener);
		add(btnViewIncome);

	}
	
	/**
	 * Adds buttons that correspond to doctor actions
	 */
	private void addDoctorBtns(){
		
		addNurseBtns();
		
		btnViewIncome = new JButton("View Income Statement");
		btnViewIncome.addActionListener(buttonListener);
		add(btnViewIncome);
		
	}
	
	/**
	 * Adds buttons that correspond to nurse actions
	 */
	private void addNurseBtns(){
		
		btnViewPatients = new JButton("View Patients");
		btnViewPatients.addActionListener(buttonListener);
		add(btnViewPatients);
		
		btnViewAppts = new JButton("View Appointments");
		btnViewAppts.addActionListener(buttonListener);
		add(btnViewAppts);
		
	}
	
	/**
	 * Adds buttons that correspond to patient actions
	 */
	private void addPatientBtns(){
	
		btnRequestAppt = new JButton("Request Appointment");
		btnRequestAppt.addActionListener(buttonListener);
		add(btnRequestAppt);
		
		btnViewAppts = new JButton("View Appointments");
		btnViewAppts.addActionListener(buttonListener);
		add(btnViewAppts);
		
		btnViewInvoice = new JButton("View Invoice");
		btnViewInvoice.addActionListener(buttonListener);
		add(btnViewInvoice);
		
		btnUpdateInfo = new JButton("Update Information");
		btnUpdateInfo.addActionListener(buttonListener);
		add(btnUpdateInfo);
		
		btnMedHistory = new JButton("View Medical History");
		btnMedHistory.addActionListener(buttonListener);
		add(btnMedHistory);
		
		btnViewWeightChart = new JButton("View Weight Chart");
		btnViewWeightChart.addActionListener(buttonListener);
		add(btnViewWeightChart);
		
	}
	
	
	
	/**
	 * ButtonListener
	 * ActionListener to listen when button has been pressed
	 *
	 *
	 *  Date           	Name            	Action
	 *  --------------------------------------------------------------------------------------
	 *	03/06/11		Bethany				Created Class
	 *
	 *
	 *
	 * @author bethanysumner
	 */
	private class ButtonListener implements ActionListener{
		
		/**
		 * Performs tasks corresponding to the action
		 * @param event The action event
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
		 */
		public void actionPerformed(ActionEvent event){
			
			if(event.getSource().equals(btnLogout)){ // <visable to everyone>
				main.logout();
			}else if(event.getSource().equals(btnRequestAppt)){ // <visable to patients>
				main.addTab("Request Appointment", new AddEditAppointment(main, main.getDatabase()));
			}else if(event.getSource().equals(btnUpdateInfo)){ // <visable to patients>
				main.addTab("Update Information", new UpdatePatient(main, main.getDatabase(), main.getCurrentUser()));
			}else if(event.getSource().equals(btnMedHistory)){ // <visable to patients>
				main.addTab("Medical History", new ViewMedicalHistory(main, main.getDatabase(), main.getCurrentUser()));
			}else if(event.getSource().equals(btnViewUsers)){ // <visable to system admins>
				main.addTab("View Users", new ViewUsers(main, main.getDatabase()));
			}else if(event.getSource().equals(btnAddNewUser)){ // <visable to system admins>
				main.addTab("Add New User", new AddEditUser(main, main.getDatabase()));
			}else if(event.getSource().equals(btnViewAppts)){ // <visable to nurse, doctor, system admin>
				main.addTab("View Appointments", new ViewAppointments(main, main.getDatabase()));
			}else if(event.getSource().equals(btnViewIncome)){ // <visable to doctor, system admin>
				main.addTab("Income Statement", new ViewIncomeStatement(main, main.getDatabase()));
			}else if(event.getSource().equals(btnViewPatients)){ // <visable to doctor, nurse>
				main.addTab("View Patients", new ViewUsers(main, main.getDatabase()));
			}else if(event.getSource().equals(btnViewInvoice)){ // <visable to patient>
				main.addTab("View Invoice", new ViewInvoice(main, main.getDatabase(), main.getCurrentUser()));
			}else if(event.getSource().equals(btnViewWeightChart)){ // <visable to patient>
				main.addTab("Weight over Time", new HealthHistoryChart(main, main.getCurrentUser(), main.getDatabase()));
				
			}
			
		}//end actionPerformed
		
	}// end ButtonListener
	

}//end SideBar class
